const _ = require('lodash');

module.exports = function(db) {
  const collection = db.collection('users');
  return {
    name: 'users',
    findOneUser: function(selector, options) {
      return collection.findOne(selector, options);
    },
    findOneAndUpdateUser: function(selector, update, options) {
      return collection.findOneAndUpdate(selector, update, options);
    },
    allRegisterUsers: function() {
      return collection.find().count();
    },
    allOnlineUsers: function() {
      return collection.find({ online: true }).count();
    },
  };
};
